package com.rules.admin.utils;


import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;

public abstract class ResultUtils {
    public static final String RESULT_SYMBOL = "RESULT_SYMBOL";

    public ResultUtils() {
    }

    public static final Map<String, Object> getFaildResultData() {
        Map<String, Object> faildResultData = new HashMap();
        faildResultData.put("success", false);
        return faildResultData;
    }

    public static final Map<String, Object> getFaildResultData(String... errorMessages) {
        Map<String, Object> faildResultData = new HashMap();
        faildResultData.put("success", false);
        faildResultData.put("errorMessages", errorMessages);
        return faildResultData;
    }

    public static final Map<String, Object> getFaildResultDataWithErrorCode(Object errorCode, String... errorMessages) {
        Map<String, Object> faildResultData = new HashMap();
        faildResultData.put("success", false);
        faildResultData.put("errorCode", errorCode);
        faildResultData.put("errorMessages", errorMessages);
        return faildResultData;
    }

    public static final Map<String, Object> getFaildResultData(Collection<String> errorMessages) {
        if (CollectionUtils.isNotEmpty(errorMessages)) {
            String[] errorMessagesAry = (String[])errorMessages.toArray(new String[errorMessages.size()]);
            return getFaildResultData(errorMessagesAry);
        } else {
            return getFaildResultData();
        }
    }

    public static final Map<String, Object> getSuccessResultData() {
        Map<String, Object> successResultData = new HashMap();
        successResultData.put("success", true);
        return successResultData;
    }

    public static final Map<String, Object> getSuccessResultData(Object data) {
        Map<String, Object> successResultData = new HashMap();
        successResultData.put("success", true);
        successResultData.put("data", data);
        return successResultData;
    }

    public static final Map<String, Object> getSuccessResultData(String root, Object data) {
        Map<String, Object> successResultData = new HashMap();
        successResultData.put("success", true);
        successResultData.put(root, data);
        return successResultData;
    }
}